package part1.language_basis.day05;

public class ForDemo {
    public static void main(String[] args) {

        for (int i = 1; i <= 9; i++) {
            if (i%3 != 0) {
                System.out.println(i + "*9=" + i * 9);
            }
        }

        //continue
        //输出9的乘法表 跳过能被3整除的
        for (int i = 1; i <= 9; i++) {
            if (i % 3 == 0) {
                continue; //跳过循环体中剩余语句直接进入下一次循环
            }
            System.out.println(i + "*9=" + i * 9);
        }


        //break
        for (int i = 1; i <= 9; i++) {
            if (i == 4) { //在某种特定条件下,提前结束循环
                break; //跳出循环 剩下的循环不走了
            }
            System.out.println(i + "*9=" + i * 9);
        }


        //累加和: 1+2+3+4+....+99+100=?
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum = sum + i;
        }
        System.out.println("sum=" + sum);
        /*
                  sum=0
           i=1    sum=1
           i=2    sum=1+2
           i=3    sum=1+2+3
           i=4    sum=1+2+3+4
           ...    sum=1+2+3+4+...
           i=99   sum=1+2+3+4+...+99
           i=100  sum=1+2+3+4+...+99+100
         */


        //累加和：1 +2 +2^2 +2^3+... +2^99 +2^100
        int sum2 = 1;
        for (int i = 1; i <= 3; i++) {
            sum2 += Math.pow(2,i);
        }
        System.out.println("幂次方和为："+sum2);

    }
}
